package club.zhilin.guli.service.edu.controller.portal;

import club.zhilin.guli.common.base.result.CommonResult;
import club.zhilin.guli.service.edu.domain.Course;
import club.zhilin.guli.service.edu.domain.Teacher;
import club.zhilin.guli.service.edu.service.ICourseService;
import club.zhilin.guli.service.edu.service.ITeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhilin
 * @since 2022/2/23 21:00
 */
@Api(tags = "首页")
@RestController
@RequestMapping("/portal/edu/index")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PortalIndexController {

    private final ICourseService iCourseService;
    private final ITeacherService teacherService;

    @ApiOperation("课程和讲师的首页管理")
    @GetMapping
    public CommonResult<Map<String, Object>> index() {
        // 查询热门课程
        List<Course> courses = iCourseService.selectHotCourse();
        // 查询推荐讲师
        List<Teacher> teachers = teacherService.selectHotTeacher();
        Map<String, Object> result = new HashMap<>(2);
        result.put("courses", courses);
        result.put("teachers", teachers);
        return CommonResult.success(result);
    }
}
